package com.transaction.simulate.controller;

import com.transaction.common.base.BaseController;
import com.transaction.common.base.PageInfo;
import com.transaction.common.util.ParamsUtil;
import com.transaction.simulate.model.dto.*;
import com.transaction.simulate.model.vo.ChannelAccountVo;
import com.transaction.simulate.service.TransService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/trans")
public class TransController extends BaseController {

    private static Logger LOGGER = LoggerFactory.getLogger(TransController.class);

    @Autowired
    private TransService transService;

    //查询交易信息
    @GetMapping("/getChannelTrans")
    public Object getChannelTrans(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        ChannelTrans channelTrans = ParamsUtil.getBeanParam(new ChannelTrans(),request);

        List<ChannelTrans> channelTransList = transService.getChannelTrans(channelTrans,pageInfo);
        pageInfo.setPageResult(channelTransList);
        return pageInfo;
    }

    @PostMapping("/deleteAll")
    public Object deleteAll(){
        transService.deleteAll();
        return retResultVo();
    }

    @PostMapping("/deleteAllElContract")
    public Object deleteAllElContract(){
        transService.deleteAllElContract();
        return retResultVo();
    }

    //生成交易数据
    @PostMapping("/generateChannelTransData")
    public Object generateChannelTransData(@RequestBody ChannelAccountVo channelAccountVo){
        transService.generateChannelTransData(channelAccountVo);
        return retResultVo();
    }


    //查询对账信息
    @GetMapping("/getReconciliation")
    public Object getReconciliation(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        Reconciliation reconciliation = ParamsUtil.getBeanParam(new Reconciliation(),request);
        List<Reconciliation> reconciliationList = transService.getReconciliation(reconciliation,pageInfo);
        pageInfo.setPageResult(reconciliationList);
        return pageInfo;
    }

    //查询分红信息
    @GetMapping("/getBonus")
    public Object getBonus(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        Bonus bonus = ParamsUtil.getBeanParam(new Bonus(),request);
        List<Bonus> bonusList = transService.getBonus(bonus,pageInfo);
        pageInfo.setPageResult(bonusList);
        return pageInfo;
    }

    @GetMapping("/getElContract")
    public Object getElContract(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        ElContract elContract = ParamsUtil.getBeanParam(new ElContract(),request);
        List<ElContract> elContractList = transService.getElContract(elContract,pageInfo);
        pageInfo.setPageResult(elContractList);
        return pageInfo;
    }

    /**
     * 查询交易确认信息
     * @param request
     * @return
     */
    @GetMapping("/getChannelTransCfm")
    public Object getChannelTransCfm(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        ChannelTransCfm channelTransCfm = ParamsUtil.getBeanParam(new ChannelTransCfm(),request);
        List<ChannelTransCfm> channelTransCfmList = transService.getChannelTransCfm(channelTransCfm,pageInfo);
        pageInfo.setPageResult(channelTransCfmList);
        return pageInfo;
    }

    @PostMapping("/deleteAllChannelTransCfm")
    public Object deleteAllChannelTransCfm(){
        transService.deleteAllChannelTransCfm();
        return retResultVo();
    }

    /**
     * 统计交易数据
     * @param request
     * @return
     */
    @GetMapping("/getTransVolStatistics")
    public Object getTransVolStatistics(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        TransVolStatistics transVolStatistics = ParamsUtil.getBeanParam(new TransVolStatistics(),request);
        List<TransVolStatistics> transVolStatisticsList = transService.getTransVolStatistics(transVolStatistics,pageInfo);
        pageInfo.setPageResult(transVolStatisticsList);
        return pageInfo;
    }

}
